package cn.itrigger.dynamic.sql.structure;

import cn.itrigger.dynamic.sql.render.TableAliasCalculator;

import java.util.Optional;

/**
 * @author admin
 * @date 2018/9/21
 **/
public interface BasicColumn {

    public Optional<String> alias();

    public BasicColumn as(String alias);

    public String renderWithTableAlias(TableAliasCalculator tableAliasCalculator);

    default String renderWithTableAndColumnAlias(TableAliasCalculator tableAliasCalculator) {
        String nameAndTableAlias = renderWithTableAlias(tableAliasCalculator);

        return alias().map(a -> nameAndTableAlias + " as " + a)
                .orElse(nameAndTableAlias);
    }
}
